<template>
	<view class="">
		<view class="my-list ">
			<u-list @scrolltolower="scrolltolower" v-if="dataList.length > 0">
				<u-list-item v-for="(item, index) in dataList" :key="index">
					<view
						class="bg-white padding-20 border-radius-10 mt-20" 
						@click="$u.route('/pages/shop/Staff/workshift', {id: item.id, staffId:seData.staffId})"
					>
						<view class="flex">
							<uni-icons custom-prefix="iconfont"  type="icon-date" size="18"/>
							<text class="ml-10">{{item.dateTitle}}</text>
						</view>
						<view class="flex mt-20">
							<uni-icons custom-prefix="iconfont"  type="icon-time" size="18"/>
							<text class="ml-10">{{item.timeStar}} - {{item.timeEnd}}</text>
						</view>
						<view class="flex justify-end">
							<u-tag text="删除该条" type="error" shape="circle" @click.stop="onDel(item, index)"/>
						</view>
					</view>
				</u-list-item>
				<u-loadmore 
					:status="loadmore.status" 
					:icon-type="loadmore.iconType" 
					:load-text="loadmore.loadText.loadText" 
					margin-top="40"
					margin-bottom="20" 
					class="coreshop-padding-top-10" 
				/>
			</u-list>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="dataList.length == 0">
			<u-empty icon-size="150" text="暂无数据" mode="data"></u-empty>
		</view>
		<uni-fab
			:popMenu="false" 
			ref="fab" 
			horizontal="right" 
			:pattern="{ buttonColor :'#e54d42' }"
			@fabClick="$u.route('/pages/shop/Staff/workshift', {staffId: userInfo.userId})"
		/>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	// import listHeightMixin from '@/common/computedAltitude.js'
	export default {
		// mixins:[listHeightMixin],
		data() {
			return {
				loadmore:{
					status: 'loadmore',
					iconType: 'flower',
					loadText: {
						loadmore: '轻轻上拉',
						loading: '努力加载中',
						nomore: '实在没有了'
					},
				},
				dataList: [],
				searchData: {
					page: 1,
					limit: 10,
					staffId:0,
				}
			}
		},
		onLoad() {
			const that = this
			this.searchData.staffId = this.userInfo.userId
			this.getPageList()
			uni.$on('upList', (ix) => {
				that.searchData.page = 1
				that.dataList = []
				that.getPageList()
			})
		},
		computed: {
			...mapState(['userInfo'])
		},
		onUnload() {
			uni.$off('upList')
		},
		methods: {
			onDel(im, ix){
				this.$reqJsonPost('StoreStaffScheduleDoDelete', {id: im.id, staffId: this.userInfo.userId}).then(res=>{
					this.dataList = this.dataList.splice(ix, 1)
				})
			},
			getPageList() {
				this.$reqPost('StoreStaffScheduleList', this.searchData).then(res => {
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.loadmore.status = 'loadmore'
						this.searchData.page++
					} else {
						// 数据已加载完毕
						this.loadmore.status = 'nomore'
					}
				})
			},
			scrolltolower() {
				if (this.loadmore.status === 'loadmore') {
					this.getPageList()
				}
			}
		}
	}
</script>
